﻿<UserControl x:Class="Mitosoft.Definitions.Views.DirectorySelectionView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:viewModels="clr-namespace:Mitosoft.Definitions.ViewModels"
             xmlns:converters="clr-namespace:WpfUIUtilities.Converters;assembly=WpfUIUtilities"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:behaviors="clr-namespace:WpfUIUtilities.Behaviors;assembly=WpfUIUtilities"
             mc:Ignorable="d" MinWidth="300">

    <UserControl.Resources>
        <converters:BooleanVisibilityConverter x:Key="BooleanVisibilityConverter" />
    </UserControl.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>

        <Label   Grid.Row="0" Grid.Column="0" Margin="10">Selected directory:</Label>
        <Label   Grid.Row="0" Grid.Column="1" Margin="10" Content="{Binding SelectedDirectory.FullPath, Mode=OneWay}" Background="Gainsboro" FontWeight="Bold" />
        <Button  Grid.Row="0" Grid.Column="2" Margin="10" Command="{Binding SelectDirectoryCommand}">...</Button>

        <TreeView Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3"
            Height="200" Margin="5"
            ItemsSource="{Binding RootDirectories}"
            Visibility="{Binding ShowDirectories, Converter={StaticResource BooleanVisibilityConverter}}"
            VirtualizingStackPanel.IsVirtualizing="True"  
            VirtualizingStackPanel.VirtualizationMode="Recycling" >
            
            <i:Interaction.Behaviors>
                <behaviors:BindableSelectedTreeViewItemBehavior SelectedItem="{Binding SelectedDirectory, Mode=TwoWay}" />
                <behaviors:PassThroughMouseWheelBehavior />
            </i:Interaction.Behaviors>

            <TreeView.ItemContainerStyle>
                <Style TargetType="{x:Type TreeViewItem}">
                    <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                </Style>
            </TreeView.ItemContainerStyle>
            
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Children}" DataType="{x:Type viewModels:ITreeViewItemViewModel}">
                    <TextBlock Text="{Binding DisplayText}" />
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
            
        </TreeView>
        
    </Grid>
</UserControl>
